package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbUserMessage;
import com.ruoyi.system.service.ITbUserMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 留言Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/message")
public class TbUserMessageController extends BaseController
{
    @Autowired
    private ITbUserMessageService tbUserMessageService;

    /**
     * 查询留言列表
     */
    @PreAuthorize("@ss.hasPermi('system:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbUserMessage tbUserMessage)
    {
        startPage();
        List<TbUserMessage> list = tbUserMessageService.selectTbUserMessageList(tbUserMessage);
        return getDataTable(list);
    }

    /**
     * 导出留言列表
     */
    @PreAuthorize("@ss.hasPermi('system:message:export')")
    @Log(title = "留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbUserMessage tbUserMessage)
    {
        List<TbUserMessage> list = tbUserMessageService.selectTbUserMessageList(tbUserMessage);
        ExcelUtil<TbUserMessage> util = new ExcelUtil<TbUserMessage>(TbUserMessage.class);
        util.exportExcel(response, list, "留言数据");
    }

    /**
     * 获取留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbUserMessageService.selectTbUserMessageById(id));
    }

    /**
     * 新增留言
     */
    @PreAuthorize("@ss.hasPermi('system:message:add')")
    @Log(title = "留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbUserMessage tbUserMessage)
    {
        return toAjax(tbUserMessageService.insertTbUserMessage(tbUserMessage));
    }

    /**
     * 修改留言
     */
    @PreAuthorize("@ss.hasPermi('system:message:edit')")
    @Log(title = "留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbUserMessage tbUserMessage)
    {
        return toAjax(tbUserMessageService.updateTbUserMessage(tbUserMessage));
    }

    /**
     * 删除留言
     */
    @PreAuthorize("@ss.hasPermi('system:message:remove')")
    @Log(title = "留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbUserMessageService.deleteTbUserMessageByIds(ids));
    }
}
